App({
    // onLaunch: function () {
    // },


    getUserInfo: function(cb) {
        var that = this
        if (this.globalData.userInfo) {
            typeof cb == "function" && cb(this.globalData.userInfo)
        } else {
            //调用登录接口
            wx.login({
                success: function(r) {
                    that.globalData.userCode = r.code;
                    wx.getUserInfo({
                        success: function(res) {
                            that.globalData.userInfo = res.userInfo
                            typeof cb == "function" && cb(that.globalData.userInfo)
                        }
                    })
                }
            })
        }
    },
    getLocation(cb) {
        var _self = this;
        var {
            lat,
            lng
        } = _self.globalData.location;

        if (!lat || !lng) {
            wx.getLocation({
                success: function(result) {
                    var lat = result.latitude;
                    var lng = result.longitude;

                    _self.globalData.location = { lat, lng };

                    cb && cb(_self.globalData.location);
                },
                fail: function(result) {}
            });
        } else {
            cb && cb(_self.globalData.location);
        }

        return this.globalData.location;
    },
    setUserSid: function(sid) {
        this.globalData.userSid = sid;
    },
    getUserSid: function() {
        return this.globalData.userSid;
    },
    setOpenId(openId) {
        this.globalData.openId = openId;
    },
    getOpenId() {
        return this.globalData.openId;
    },
    setShopSid(shopSid) {
        this.globalData.shopSid = shopSid;
    },
    getShopSid() {
        return this.globalData.shopSid;
    },

    globalData: {
        openId: '',
        userSid: '',
        userInfo: null,
        shopSid:null,
        location: {
            lng: '',
            lat: '',
        }
    },
    config: {
        // appSecret:'20fe10c45d2e52d4e4494a94af4bfa5f',/*这个是secret,小程序里用不到。在这里存一下。*/
        // apiUrl:'https://api.y.88ff.com'
        // apiUrl: 'https://newapi.duoy1.cn',
        // apiUrl: 'https://vip.duoy1.cn',
        // apiUrl: 'https://api.yun.taojinzi.cn',
        apiUrl:'https://shitilian.duoy1.cn',
        shareTitle: '共享商家优惠，支付即营销'
    }
})